home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / IFF / Old_IFF_Packages / November_1988 / Examples / PGTB / tbrutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-12  |  1.8 KB  |  89 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /* |_o_o|\\  The Software Distillery                       */
  3. /* |. o.| || Made available to the Amiga development community           */
  4. /* | o    | || the authors:                     BBS:       */
  5. /* |  . |//    John Mainwaring                   (919)-471-6436  */
  6. /* ======                                   */
  7. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  8.  
  9. /* Utilities used to read both traceback dump and code files.  Defines a     */
  10. /* longjump buffer used to bail out on read errors.  Users desiring sane     */
  11. /* error handling would be well advised to initialize it via setjmp.         */
  12.  
  13. #include "tb.h"
  14. #include "setjmp.h"
  15.  
  16. jmp_buf bailout;
  17.  
  18. long getlong(file)
  19. /*   -------    */
  20. FILE *file;
  21. {
  22. long buffer;
  23.  
  24. if (fread((char *)&buffer, 1, 4, file) != 4)
  25.    {
  26.    fprintf(stderr, "unexpected EOF\n");
  27.    longjmp(bailout, 1);
  28.    }
  29.  
  30. return buffer;
  31. }
  32.  
  33. long forcegetlong(file)
  34. /*   -----------*/
  35. /* don't longjmp on EOF or error - return 0 to caller which is treated  */
  36. /* as a termination condition.                        */
  37. FILE *file;
  38. {
  39. long buffer;
  40.  
  41. if (fread((char *)&buffer, 1, 4, file) != 4)
  42.    return 0;
  43. else
  44.    return buffer;
  45. }
  46.  
  47. void getblock(file, buffer, size)
  48. /*   --------               */
  49. FILE *file;
  50. ULONG *buffer;
  51. long size;
  52. {
  53. size <<= 2;
  54. if (fread((char *)buffer, 1, size, file) != size)
  55.    {
  56.    fprintf(stderr, "unexpected EOF\n");
  57.    longjmp(bailout, 1);
  58.    }
  59. }
  60.  
  61. ULONG getascii(file, buffer)
  62. /*   --------               */
  63. FILE *file;
  64. char **buffer;
  65. {
  66. ULONG size;
  67.  
  68. size = getlong(file);
  69. if (!(*buffer = AllocMem(size<<2, MEMF_CLEAR)))
  70.    {
  71.    fprintf(stderr, "*** unable to allocate memory\n");
  72.    exit(FATAL);
  73.    }
  74. getblock(file, (ULONG *)*buffer, size);
  75. return(size);
  76. }
  77.  
  78. void skiplong(file, size)
  79. /*   --------           */
  80. FILE *file;
  81. long size;
  82. {
  83. if (fseek(file, size*4, 1) == -1)
  84.    {
  85.    fprintf(stderr, "unexpected EOF\n");
  86.    longjmp(bailout, 1);
  87.    }
  88. }
  89.